import { Injectable } from '@angular/core';
import {HEROES, Hero} from "./mock-heroes";

@Injectable()
export class HeroServiceService {

  constructor() { }

  getHeros():Promise<Hero[]>{
    return Promise.resolve(HEROES);
  }

  getHeroesSlowly(): Promise<Hero[]> {
    return new Promise(resolve => {
      setTimeout(() => resolve(HEROES), 2000);
    });
  }

  getHero(id: number): Promise<Hero> {
    return this.getHeros()
      .then(heroes => heroes.find(hero => hero.id === id));
  }
}
